/*
 * =====================================================================================
 *
 *       Filename:  rabbits.c
 *
 *    Description:  calculate rabbits number by month
 *
 *        Created:  2020-07-10 11:13
 *
 *         Author:  limingle
 *          Email:  lml@xdja.com
 *   Organization:  XDJA Tech.CO.ltd.
 *
 * =====================================================================================
 */

#include <stdio.h>

/*
 *  rabbits(month n) = adult_rabbits(month n) +
 *                     young_rabbits(month n) +
 *                     baby_rabbits(month n)
 *
 *  adult_rabbits(month n)  = adult_rabbits(month n-1) + young_rabbits(month n-1)
 *  young_rabbits(month n)  = baby_rabbits(month n-1)
 *  baby_rabbits(month n)   = adult_rabbits(month n-1) + young_rabbits(month n-1)
 *
 *  adult_rabbits(0) = 0; young_rabbits(0) = 0; baby_rabbits(0) = 1;
 *
 */
size_t rabbits(size_t adult, size_t young, size_t baby, unsigned months_left)
{
    if (months_left == 0)
    {
        return adult + young + baby;
    }
    else
    {
        return rabbits(adult + young, baby, adult + young, months_left - 1);
    }
}

size_t rabbits_num(int nth_month)
{
    size_t adult = 0;
    size_t young = 0;
    size_t baby = 1;
    return rabbits(adult, young, baby, nth_month);
}

int main(int argc, const char *argv[])
{
    printf("pairs of rabbits number after (12 - 1) months: %lu\n", rabbits_num(12 - 1));
    return 0;
}
